package com.example.bookkeeping1220;

import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.bookkeeping1220.AchievementActivity;
import com.example.bookkeeping1220.R;
import com.example.bookkeeping1220.adapter.AccountAdapter;
import com.example.bookkeeping1220.adapter.AchievementAdapter;
import com.example.bookkeeping1220.adapter.HeadportraitAdapter;
import com.example.bookkeeping1220.db.AchievementBean;
import com.example.bookkeeping1220.db.DBManager;
import com.example.bookkeeping1220.db.HeadportraitBean;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class HeadportraitActivity extends AppCompatActivity {
    private GridView headGv;
    HeadportraitAdapter headportraitAdapter;
    List<HeadportraitBean> headDatas;  //成就的bean
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_headportrait);
        headGv = findViewById(R.id.headportrait_show);
        buildHeadDatas();
        headportraitAdapter = new HeadportraitAdapter(HeadportraitActivity.this,headDatas);
        headGv.setAdapter(headportraitAdapter);
        setGVLongClickListener();
    }

    /*点击事件*/
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.headportrait_iv_back:
                finish();
                break;
        }
    }

    /** 设置GridView的点击事件*/
    private void setGVLongClickListener() {
        headGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                HeadportraitBean clickBean = headDatas.get(i);  //获取正在被点击的这条信息
                //弹出提示用户的对话框
                showItemDialog(clickBean);
            }
        });
    }
    private void showItemDialog(HeadportraitBean clickBean) {
        DBManager.setHead(clickBean.getsImageId(),clickBean.getHeadName());
        finish();
    }


    /*头像不多，简单加载就好*/
    private void buildHeadDatas() {
        headDatas = new ArrayList<>();
        headDatas.add(new HeadportraitBean(0,"1",R.drawable.portrait_1));
        headDatas.add(new HeadportraitBean(1,"2",R.drawable.portrait_2));
        headDatas.add(new HeadportraitBean(2,"3",R.drawable.portrait_3));
        headDatas.add(new HeadportraitBean(3,"4",R.drawable.portrait_4));
        headDatas.add(new HeadportraitBean(4,"5",R.drawable.portrait_5));
        headDatas.add(new HeadportraitBean(5,"6",R.drawable.portrait_6));
        headDatas.add(new HeadportraitBean(6,"7",R.drawable.portrait_7));
        headDatas.add(new HeadportraitBean(6,"8",R.drawable.portrait_8));
        headDatas.add(new HeadportraitBean(6,"超级帅的",R.drawable.portrait_9));
        headDatas.add(new HeadportraitBean(6,"10",R.drawable.portrait_10));
        headDatas.add(new HeadportraitBean(6,"11",R.drawable.portrait_11));
    }
}
